function hide_alert(){
	//$(".zzblock").css("display","none");
	//location.href='wapOrderDetails.php';	
	var order_id=$('#orderId').val();
	var re_type=$('#orderType').val();
	var xiyi = $('#xiyi').val();
	cancel_order(order_id,re_type,xiyi);
}
function hide_del_alert(){
	
	var sid=$('#sId').val();
	 
	remove_service(sid);
}
function hide_box(){
	$(".zzblock").css("display","none");
	var xiyi = $('#xiyi').val();

	if(xiyi == 'xiyi'){
		location.href="myXiYiDriver.php";
	} else {
		location.href="myDriver.php";
	}
	
}
function cancel_alert(){
	$(".zzblock").css("display","none");
}
//删除服务

function del_service(sid){
	
	$(".zzblock").css("display","block");
	$("#alertMsg").html('您确认删除此服务记录吗?<br/><br/>');
	$('#sId').val(sid);
}

function remove_service(sid){
	$.ajax({
		type:"post",
		url:"mobile.php?act=module&name=huijiajie&do=removeservice&weid=1",
		data:"t="+new Date()+"&sid="+sid+"",
		dataType:"html",
		success:function(msg){
			//alert(msg);
			if(msg=='2'){
					
					location.href='';
				
				 
				//alert('取消成功');
				//$(".zzblock").css("display","block");
				//$("#alertMsg").html('取消成功<br/><br/>');
			}else {
				//alert('取消失败');
				$(".zzblock").css("display","block");
				$("#alertMsg").html('取消失败<br/><br/>');
			}
		}
	});
}
//取消订单
function make_cancel(order_id){
	$(".zzblock").css("display","block");
	$("#alertMsg").html('您确认取消此订单吗?<br/><br/>');
	$('#orderId').val(order_id);
}
function cancel_order(order_id,re_type,xiyi){
	$.ajax({
		type:"post",
		url:"mobile.php?act=module&name=huijiajie&do=cancelorder&weid=1",
		data:"t="+new Date()+"&order_id="+order_id+"",
		dataType:"html",
		success:function(msg){
			//alert(msg);
			if(msg=='2'){
					
					location.href='';
				
				 
				//alert('取消成功');
				//$(".zzblock").css("display","block");
				//$("#alertMsg").html('取消成功<br/><br/>');
			}else {
				//alert('取消失败');
				$(".zzblock").css("display","block");
				$("#alertMsg").html('取消失败<br/><br/>');
			}
		}
	});
}
//恢复订单
function restore_order(order_id){
	//alert(order_id);
	$.ajax({
		type:"post",
		url:"mobile.php?act=module&name=huijiajie&do=restoreorder&weid=1",
		data:"t="+new Date()+"&order_id="+order_id+"",
		dataType:"html",
		success:function(msg){
			if(msg=='2'){
				alert('恢复成功');
				// $(".zzblock").css("display","block");
				// $("#alertMsg").html('恢复成功<br/><br/>');
				location.href='';
			}else if(msg=='1'){
				//alert('恢复失败');
				$(".zzblock").css("display","block");
				$("#alertMsg").html('恢复失败<br/><br/>');
			}
		}
	});
}

//确认/点评订单
//function commentsOrder(){
$("document").ready(function(){
	
	//点评
	$("#star").val("5");
	$("#firstSelect,#twoSelect,#threeSelect").click(function(){
		$("#firstSelect,#twoSelect,#threeSelect").removeClass('select');
		$(this).addClass('select');
		var t=$(this).attr("typesrc");
		if(t=='a1')
		{
			$("#star").val("5");
		}
		else if(t=='a2')
		{
			$("#star").val("3");
		}
		else if(t=='a3')
		{
			$("#star").val("1");
		}
	})
	//投诉
	$("#complain").val("1");
	$("#firstSrc,#twoSrc,#threeSrc,#fourSrc").click(function(){
		$("#firstSrc,#twoSrc,#threeSrc,#fourSrc").removeClass('default');
		$(this).addClass('default');
		var t=$(this).attr("typesrc");
		if(t=='t1')
		{
			$("#complain").val("1");
		}
		else if(t=='t2')
		{
			$("#complain").val("2");
		}
		else if(t=='t3')
		{
			$("#complain").val("3");
		}
		else if(t=='t4')
		{
			$("#complain").val("4");
		}
	})
	//提交
	$("#submitbtn").click(function(){
		//alert('ads');
		var content=$('#complain_text').val();
		if(content=='' || content=='请输入您的投诉详情'){
			$(".zzblock").css("display","block");
			$("#alertMsg").html('请输入投诉内容<br/><br/>');
			return false;
		}
		$("#doform").submit();
	})
})
	
//}

function phone_onchange(){
	var phone=$("#phone").val();
	var oldheight=$("#menu").height();
	if(phone.length==11){
		$("#verify_code_box").show();
		var nowheight=oldheight+50;
		$("#menu").height(nowheight);
	}
	else{
		$("#verify_code_box").hide();
		$("#menu").height(oldheight);
	}
}

function orderbuttonclick(){
	var test_tree_list_dummy_val=$("#test_tree_list_dummy").val();
	var address=$("#address").val();
	var phone=$("#phone").val();
	var increaseval=$("#additional").val();
	var res_verify_code=$("#res_verify_code").val();
	var city=$("#city").val();
	if(city==''){city='131'};
	var curLatitude='111';
	var curLongitude='222';
	var d = new Date();
	var vYear = d.getFullYear();
	var vMon = d.getMonth() + 1;
	var vDay = d.getDate();
	var vHouse=d.getHours();
	var vMin=d.getMinutes();
	var vSend=d.getSeconds();
	var datetounixval=DateToUnix(vYear,vMon,vDay,vHouse,vMin,vSend);
	var addressstate=getByteLen(address);

	if(addressstate>3){
		$.ajax({
			type:"post",
			url:"ajaxapi/requestOrder.php",
			data:"clientOrderId="+datetounixval+"&session_id=16c0aeb179c79d392839d572169f9c82-145&latitude="+curLatitude+"&longitude="+curLongitude+"&detailAddress="+address+"&time="+test_tree_list_dummy_val+"&userAddMoney="+increaseval+"&telephone="+phone+"&res_verify_code="+res_verify_code+"&city="+city,
			dataType:"html",
			success:function(msg){
			    var json=eval("("+msg+")");
			    var id='resmsg';
			    if(json.result=='1'){
		        	divshowmsgshow(id,json.msg);
			    }
			    else{
					divshowmsgshow(id,json.message);
			    }
			}
		  })
		}
		else{
			var textval='请输入有效地址';
			var id='resmsg';
		    divshowmsgshow(id,textval);
		}
}

	/*我的订单按键功能*/
	function myorderlist(){
		var phone=getCookie('telephone');
		var session_id=getCookie('session_id');

		var tele= /^1[3|4|5|6|7|8][0-9]\d{4,8}$/;
		var phoneResult=tele.test(phone);

		if(phoneResult && session_id!=''){

		var isOnMyOrder=1;
		$.ajax({
			type:"post",
			url:"ajaxapi/Procter_history_sql.php",
			data:"id="+new Date()+"&telephone="+phone+"&session_id="+session_id,
			dataType:"html",

			success:function(msg){
			    var json=eval("("+msg+")");

					if(isOnMyOrder==1){
						$("#myorderulbox").html("");
						//$("#record").html(json.num);
						var data=json.driver;
						$.each(data, function(k, v){

						var evaluate_stat='';
						var order_state=data[k]['state'];

						/*下方是时间格式的转换*/

						if(order_state>1 && order_state<9){
							var procter_working_status="已接单";

							//var headurlval=this.head_url;
							//var strurl="http://static.1jiajie.com/ayiheadurl/"+this.head_url;

							if(data[k]['head_url']==''){
								data[k]['head_url']="/gaodewebapp/images/u8.png";
							}
							var prohis="<li id=order"+data[k]['order_id']+" class='myorderpmargin B9B9B5line bcffffff height100'><div class='widthseventy floatleft' style='margin:15px auto 0 10px;'><img src='images/u8.png' class='imgwidth' /></div><div class='floatleft leftmargintwenty margintopten width180'><div class='myorderdata fsfont12 margintoptwo'>"+data[k]['create_time']+
									   "</div><div class='myorderdata fsfont12 margintoptwo'><span>状态: </span><pan> 已保洁</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>保洁阿姨: </span><span>"+data[k]['driver_name']+
									   "</span></div><a href=Tel:"+data[k]['driver_phone']+"><div class='textcenter odbutbgfourty fsfont12 borderradius20 floatleft' style='margin:15px auto 0 0;'>呼叫阿姨</div></a><!--<div class='textcenter odbutbgfourty fsfont12 borderradius20 B9B9B5line floatleft' style='margin:15px auto 0 6px;'>点 评</div>--></div><div class='floatright widthten heightfourty margintopthrty rightmarginten'><img src='images/Icon2x.png' class='imgwidth'></div></li>";
	 						$("#myorderulbox").append(prohis);
						}
						else if(order_state==1 || order_state==0){
							var prohis="<li id=order"+data[k]['order_id']+" class='myorderpmargin B9B9B5line bcffffff height100'><div class='widthseventy floatleft' style='margin:15px auto 0 10px;'><img src='images/u8.png' class='imgwidth' /></div><div class='floatleft leftmargintwenty margintopten'><div class='myorderdata fsfont12 margintoptwo'>"+data[k]['create_time']+
							"</div><div class='myorderdata fsfont12 margintoptwo'>待应征订单</div><div class='myorderdata fsfont12 margintoptwo'>阿姨应征中,30分钟内阿姨会联系您</div><div class='textcenter odbutbgtwoty fsfont12 borderradius20 B9B9B5line' style='margin:4px auto 0 0;' onclick=cancelorder("+data[k]['order_id']+")>取 消</div></li>";
							$("#myorderulbox").append(prohis);
						}
						else if(order_state>7){
							var prohis="<li id=order"+data[k]['order_id']+" class='myorderpmargin B9B9B5line bcffffff height100'><div class='widthseventy floatleft' style='margin:15px auto 0 10px;'><img src='images/u8.png' class='imgwidth' /></div><div class='floatleft leftmargintwenty margintopten width180'><div class='myorderdata fsfont12 margintoptwo'>"+data[k]['create_time']+
									   "</div><div class='myorderdata fsfont12 margintoptwo'><span>状态: </span><pan> 已取消</span></div></div><div class='floatright widthten heightfourty margintopthrty rightmarginten'><img src='images/Icon2x.png' class='imgwidth'></div></li>";
							$("#myorderulbox").append(prohis);
						}
					})
				}
				$("#myorderulbox").append("<br/>");
				$("#myorderulbox li:even").css("background-color","#EAF8F3");
			}
		})
	}
	else{
		//alert('ok');
		$.mobile.changePage($("#login"), "slideup");
	}
}

function headerpricehelp(){
	$(".headerpricehelp").addClass("ui-btn-active");
}

function headerpricetext(){
	$(".headerpricetext").addClass("ui-btn-active");
}

function reservationpage(){
	removeClassFun();
	$(".reservationpage").addClass("ui-btn-active");
}

function myorderpage(){
	removeClassFun();
	$(".myorderpage").addClass("ui-btn-active");
	$("#myorderulbox li:even").css("background-color","#ffffff");

	var phone=getCookie('telephone');
	var session_id=getCookie('session_id');

	var tele= /^1[3|4|5|6|7|8][0-9]\d{4,8}$/;
	var phoneResult=tele.test(phone);
	if(phoneResult && session_id!=null){
		myorderlist();
		$.mobile.changePage($("#myorder"), "slide");
		$("#myorderulbox li:even").css("background-color","#EAF8F3");
	}
	else{
		$.mobile.changePage($("#login"), "slideup");
	}
}

function removeClassFun(){
	$(".reservationpage").removeClass("ui-btn-active");
	$(".myorderpage").removeClass("ui-btn-active");
	$(".peripherypage").removeClass("ui-btn-active");
}

$(function(){
            var curr = new Date().getFullYear();
            var opt = {};
		    opt.date = {preset : 'date'};
		    opt.datetime = { preset : 'datetime', minDate: new Date(2012,3,10,9,22), maxDate: new Date(2014,7,30,15,44), stepMinute: 5  };
			opt.time = {preset : 'time'};
			opt.tree_list = {preset : 'list', labels: ['哪天', '小时', '分钟']};
			opt.select = {preset : 'select'};

			//var telephone = getCookie('telephone');
			//$("#telephone").val(telephone);					//获取cookie电话
			//$("#phone").val(telephone);						//获取cookie电话

				var demo = $('#demo').val();
                $(".demos").hide();
                if (!($("#demo_"+demo).length))
                    demo = 'default';
                $("#demo_" + demo).show();
            	$('#test_'+demo).val('').scroller('destroy').scroller($.extend(opt['tree_list'], { theme: $('#theme').val(), mode: $('#mode').val(), display: $('#display').val(), lang: $('#language').val() }));

});


		function show(){
			var textval=$("#test_tree_list_dummy").val();
			if(textval.length<7 && textval.length>0){
				var timevalval=IgnoreSpaces(textval);
				$("#test_tree_list_dummy").val(timevalval);
			}
		}

		function clearmyinterval(){
			clearInterval(myInterval);
		}

		function IgnoreSpaces(Str){
		     var Temp=Str.split(" "); //双引号之间是个空格；
		     var timeval='';
			 var textone=Temp[0];
			 var texttwo=Temp[1];
			 var textthr=Temp[2];

			 var md='';
			 if(textone=='0'){
			 	md=GetDateStr(0);					//今天
			 }
			 else if(textone=='1'){
			 	md=GetDateStr(1);					//明天
			 }
			 else if(textone=='2'){
			 	md=GetDateStr(2);					//后天
			 }

			 var hh='';
			 	 hh=parseInt(texttwo)+7;
			 var mm='';

			 if(textthr=='0'){
			 	mm='00';
			 }
			 else if(textthr=='1'){
			 	mm='30';
			 }

			return md+" "+hh+":"+mm;
		}

		function GetDateStr(AddDayCount)
		{
			var dd = new Date();
			dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
			//var y = dd.getYear();
			var m = dd.getMonth()+1;//获取当前月份的日期
			var d = dd.getDate();
			return m+"-"+d;
		}

		function Increasebutton(idval){
			var additional='0';
			switch(idval){
				case 'incand0':
				additional ='0';
				allcolorD();
				$("#incand0").css("background","#EBAC15");
				$("#incand0").css("color","#ffffff");
				break;
				case 'incand5':
				additional ='5';
				allcolorD();
				$("#incand5").css("background","#EBAC15");
				$("#incand5").css("color","#ffffff");
				 break;
				case 'incand10':
				allcolorD();
				$("#incand10").css("background","#EBAC15");
				$("#incand10").css("color","#ffffff");
				additional ='10';
				 break;
				case 'incand20':
				allcolorD();
				$("#incand20").css("background","#EBAC15");
				$("#incand20").css("color","#ffffff");
				additional ='20';
				 break;
				 default:
			}
			$("#additional").val(additional);
		}

		function allcolorD(){
			$("#incand0").css("background","#D2DDD9");
			$("#incand0").css("color","#000000");
			$("#incand5").css("background","#D2DDD9");
			$("#incand5").css("color","#000000");
			$("#incand10").css("background","#D2DDD9");
			$("#incand10").css("color","#000000");
			$("#incand20").css("background","#D2DDD9");
			$("#incand20").css("color","#000000");
		}

		function DateToUnix(year, month, day, hour, minute, second){
			var oDate =new Date(Date.UTC(parseInt(year),parseInt(month), parseInt(day),
				parseInt(hour), parseInt(minute),
				parseInt(second)
				)
			);
			return (oDate.getTime()/1000);
		}

		function getByteLen(val) {

			var len = 0;

			for (var i = 0; i < val.length; i++) {

			if (val[i].match(/[^x00-xff]/ig) != null) //全角

			len += 2;

			else

			len += 1;
			}
			return len;
		}

		/*显示提示框*/
		function divshowmsgshow(id,msg){
			var boxwidthtwo=weixinwidth()/2;
			var boxheighttwo=weixinheight()/2;
			if(id=='loginbutton'){
				$("#resmsg").css("left",boxwidthtwo-120).css("top",boxheighttwo-70).show();
			}
			if(id=='loginbuttwo'){
				$("#divshowmsglogin").css("left",boxwidthtwo-120).css("top",boxheighttwo-70).show();
			}
			if(id=='myordermsg'){
				$("#myordermsg").css("left",boxwidthtwo-120).css("top",boxheighttwo-70).show();
			}
			if(id=='resmsg'){
				$("#resmsg").css("left",boxwidthtwo-120).css("top",boxheighttwo-70).show();
			}
			$(".divshowmsgtext").html(msg);
		}

		function weixinwidth(){
			var boxwidth  =($(window).width());
			return boxwidth;
		}
		function weixinheight(){
			var boxheight  =($(window).height());
			return boxheight;
		}

		$("#smgsub").click(function(){
			$(".divshowmsg").hide();
		})

		function showmsgtextcont(str){
			$(".divshowmsgtext").html(str);
		}

		function get_login_code(){									//为手机号获取验证码  验证点击
			var telephone=$("#phone").val();
			var tele= /^1[3|4|5|6|7|8][0-9]\d{4,8}$/;
			var phoneResult=tele.test(telephone);
			var id='resmsg';
			if(phoneResult){
				$.ajax({
					type:"post",
					url:"ajaxapi/get_login_code.php",
					data:"telephone="+telephone,
					dataType:"html",
					success:function(msg){
					    var json=eval("("+msg+")");
					    if(json.result==1){
					    	divshowmsgshow(id,json.msg);
						    setCookie('telephone', telephone);
					    }
					}
				});
			}
			else{
			    var msgtext='请您输入有效的手机号码，然后点击获取';
				divshowmsgshow(id,msgtext);
			}

		}

		function verify_code(){
																//同时发生手机号和验证码
			var telephone=$("#telephone").val();
			var verify_code=$("#verify_code").val();

			var tele= /^1[3|4|5|6|7|8][0-9]\d{4,8}$/;
			var phoneResult=tele.test(telephone);

			if(phoneResult && verify_code!=''){
				$.ajax({
					type:"post",
					url:"ajaxapi/verify_code.php",
					data:"telephone="+telephone+"&verify_code="+verify_code,
					dataType:"html",
					success:function(msg){
				    var json=eval("("+msg+")");
					   if(json.success==1){
							alert('亲~欢迎你回来');
							setCookie('session_id',verify_code);
							setCookie('telephone',telephone);
							$.mobile.changePage($("#myorder"), "slideup");
							myorderlist();
							removeClassFun();
							$(".myorderpage").addClass("ui-btn-active");
					   }

					   if(json.success==0){
					   		alert('验证码错误,请从新输入验证码');
					   }
					}
				});
			}
			else{
				  alert('请输入您的电话号和验证码');
			    }
		    }

	function userInfoPage(driverid){
		var dirvercontent='driver_name'+driverid;
		$.mobile.changePage($("#userInfo"), "slideup");
	}

	function smgsubclick(){
		$(".divshowmsg").hide();
	}

	function setCity(city){
		$("#city").val(city);
	}


